﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using ConnectionLayer;
using System.Windows.Forms;

namespace BusinessLayer
{
    public static class VeiculoActions
    {
        public static bool CriarVeiculo(String Matricula, String Marca, String Modelo, String NomeProprietario)
        {
            ConnectionFactory con = new ConnectionFactory();

            try
            {
                con.GetConnection.Open();
                SqlCommand cmd = con.GetConnection.CreateCommand();
                cmd.CommandText = "insert into veiculo(matricula,marca,modelo,nomeProprietario) values(@Matricula,@Marca,@Modelo,@NomeProprietario)";
                cmd.Parameters.AddWithValue("@Matricula", Matricula);
                cmd.Parameters.AddWithValue("@Marca", Marca);
                cmd.Parameters.AddWithValue("@Modelo", Modelo);
                cmd.Parameters.AddWithValue("@NomeProprietario", NomeProprietario);
                int numRows = cmd.ExecuteNonQuery();
                return numRows > 0;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                return false;
            }
            finally
            {
                try
                {
                    con.GetConnection.Close();
                }
                catch (Exception e) { MessageBox.Show(e.Message); }
            }
        }
    }
}
